﻿@{
    ViewBag.Title = "ShowWMItemRepcot";
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Demo</title>
    <!-- 引入 layui.css -->
    <link href="//unpkg.com/layui@2.9.17/dist/css/layui.css" rel="stylesheet">
</head>
<body>
    <form class="layui-form" action="">
        <div class="layui-form-item">

            <label class="layui-form-label">入库单编码</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="RecptCode" lay-verify="required" placeholder="请输入入库单编码" autocomplete="off" class="layui-input">
            </div>

            <label class="layui-form-label">入库单名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="RecptName" lay-verify="required" placeholder="请输入入库单名称" autocomplete="off" class="layui-input">
            </div>

             <label class="layui-form-label">供应商名称</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="VendorName" lay-verify="required" placeholder="请输入供应商名称" autocomplete="off" class="layui-input">
            </div>

             <label class="layui-form-label">订单编号</label>
            <div class="layui-input-inline layui-input-wrap">
                <input type="text" id="PoCode" lay-verify="required" placeholder="请输入订单编号" autocomplete="off" class="layui-input">
            </div>

            <div>
                 <label class="layui-form-label">入库日期</label>
            <div class="layui-input-inline layui-input-wrap">
                 <input type="text" class="layui-input" id="RecptDate" placeholder="yyyy-MM-dd HH:mm:ss">
            </div>
            </div>
           

            <button type="button" id="getWMItemRepcot" class="layui-btn layui-bg-blue">搜索</button>
            <button type="reset" id="restWMItemRepcot" class="layui-btn">重置</button>

        </div>
        <button type="button" class="layui-btn layui-btn-primary  layui-bg-blue" lay-on="layui-badge-dot">添加</button>
        <button type="button" class="layui-btn layui-bg-orange" lay-event="upd">修改</button>
        <button type="button" class="layui-btn layui-bg-red" lay-event="del">删除</button>
        <table class="layui-hide" id="WMItemRepoct" lay-filter="test">
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
        </script>
    </form>

    <!-- 引入 layui.js -->
    <script src="~/libs/jquery/jquery.js"></script>
    <script src="//unpkg.com/layui@2.9.17/dist/layui.js"></script>
    @*  显示 *@
    <script>

        layui.use(['laydate', 'laypage', 'layer', 'table', 'carousel', 'upload', 'element', 'slider'], function () {
            var layer = layui.layer //弹层
                , table = layui.table //表格
                , util = layui.util
                , datas = [];
            var $ = layui.$;
            var form = layui.form;
             var laydate = layui.laydate;
             laydate.render({
                elem: '#RecptDate',
                type: 'datetime'
             });
             //显示
            showWMItemRepcot = function () {
                layui.use(function () {
                    // 创建表格实例
                    table.render({
                        elem: '#WMItemRepoct',
                        url: '/WMItemRepoct/GetWMitemRecpt', // 此处为静态模拟数据，实际使用时需换成真实接口
                        where: {
                            RecptCode: $("#RecptCode").val(),
                            RecptName: $("#RecptName").val(),
                            VendorName: $("#VendorName").val(),
                            PoCode: $("#PoCode").val(),
                            RecptDate: $("#RecptDate").val(),
                        },
                        cols: [[
                            { type: 'checkbox', fixed: 'left'},
                            { field: 'RecptCode', title: '入库单编号' },
                            { field: 'RecptName', title: '入库单名称' },
                            { field: 'VendorName', title: '供应商名称' },
                            { field: 'RecptDate', title: '入库日期' },
                            { field: 'PoCode', title: '采购订单号' },
                            { field: 'Status', title: '单据状态' },                          
                            { fixed: "right", title: '操作', align: 'center', toolbar: '#barDemo' }
                        ]],
                        done: function () {
                            var id = this.id;
                            table.on('checkbox(test)', function (obj) {
                                datas.push(obj.data);
                            });
                        }
                    });
                });
            }
            //显示
            showWMItemRepcot();
            //查询
            $("#getWMItemRepcot").on("click", function () {
                showWMItemRepcot();
            })
            //重置
            $("#restWMItemRepcot").on("click", function () {
                showWMItemRepcot();
            })

              //添加
            util.on('lay-on', {
                'layui-badge-dot': function () {
                    layer.open({
                        type: 2,
                        area: ['800px','500px'],
                        resize: false,
                        shadeClose: true,
                        title: '添加车间',
                        content: `https://localhost:44311/WMItemRepoct/AddWMItemRepcot`,
                        btn:['确定','取消'],
                        yes: function (index, layero) {
                            var data = layer.getChildFrame('body', index).find('form').serialize();
                            console.log(data);
                                    $.ajax({
                                        url: "/WMItemRepoct/AddWMitemRecpt",
                                        type: "post",
                                        async: true,
                                        data: data,
                                        contentType: "application/json",
                                        success: res => {
                                            if (res != null) {
                                                alert("添加成功")
                                                //关闭弹出层
                                                layer.closeAll();
                                                //刷新表格
                                                showWMItemRepcot();
                                                return;
                                            }
                                            else {
                                                console.log(res.code)
                                                alert("添加失败")
                                            }
                                        }
                                    });
                                    return false; // 阻止默认 form 跳转
                                }
                        })
                        }
                    });

        });
    </script>
</body>
</html>